math *900

Please click on ads to support us..

Python Code:

n=int(input())
lis=[0 for _ in range(n)]
for i in range(n):
    lis[i]=list(map(int,input().split()))
for i in range(n):
    n=lis[i][0]
    m=lis[i][1]
    if n==1 and m==1:
        print(0)
    elif n==1 or m==1:
        print(1)
    else: print(2)

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        if(n==1 && m==1)cout<<0<<endl;
        else if(min(n,m)==1)cout<<1<<endl;
        else cout<<2<<endl;
    }
}




Comments

Submit
0 Comments
More Questions

1729D - Friends and the Restaurant
1606C - Banknotes
580C - Kefa and Park
342A - Xenia and Divisors
1033A - King Escape
39D - Cubical Planet
1453A - Cancel the Trains
645A - Amity Assessment
1144A - Diverse Strings
1553B - Reverse String
1073A - Diverse Substring
630N - Forecast
312B - Archer
34D - Road Map
630I - Parking Lot
160B - Unlucky Ticket
371B - Fox Dividing Cheese
584B - Kolya and Tanya
137B - Permutation
550C - Divisibility by Eight
5A - Chat Servers Outgoing Traffic
615A - Bulbs
5B - Center Alignment
549A - Face Detection
535B - Tavas and SaDDas
722C - Destroying Array
366A - Dima and Guards
716B - Complete the Word
1461C - Random Events
1627A - Not Shading